home *** CD-ROM | disk | FTP | other *** search
- Listing 7 - A simple application using shapes
-
- const shape *largest(const shape *sa[], size_t n)
- {
- const shape *s = 0;
- double m = 0;
- for (size_t i = 0; i < n; ++i)
- if (sa[i]->area() > m)
- {
- m = sa[i]->area();
- s = sa[i];
- }
- return s;
- }
-
- int main()
- {
- const int N = 4;
- const shape *s[N];
- const shape *ls;
- s[0] = new circle(shape::RED, 2);
- s[1] = new rectangle(shape::BLUE, 5, 6));
- s[2] = new rectangle(shape::RED, 3, 4);
- s[3] = new circle(shape::GREEN, 3);
- cout << "The shapes are:\n";
- for (int i = 0; i < N; ++i)
- cout << i << ")\t" << *s[i] << '\n';
- cout << '\n';
- ls = largest(s, N);
- cout << "The shape with the largest area is a...\n\t";
- cout << *ls << ".\n";
- cout << "Its area is " << ls->area() << ".\n";
- return 0;
- }
-
-